package rad.framework.mda.generator.template.main.java.service;

import java.util.*;
import rad.framework.mda.generator.util.*;
import org.eclipse.emf.codegen.util.*;

public class ServiceStatelessSessionBean
{
  protected static String nl;
  public static synchronized ServiceStatelessSessionBean create(String lineSeparator)
  {
    nl = lineSeparator;
    ServiceStatelessSessionBean result = new ServiceStatelessSessionBean();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "";
  protected final String TEXT_2 = "/*" + NL + " * ============================================================================" + NL + " *                   GNU Lesser General Public License" + NL + " * ============================================================================" + NL + " */" + NL + "package ";
  protected final String TEXT_3 = ";";
  protected final String TEXT_4 = NL;
  protected final String TEXT_5 = NL;
  protected final String TEXT_6 = NL + NL + "/**" + NL + " * ";
  protected final String TEXT_7 = NL + " *" + NL + " * @author ";
  protected final String TEXT_8 = NL + " * @generated" + NL + " */" + NL + "@Name(\"";
  protected final String TEXT_9 = "\")" + NL + "@AutoCreate";
  protected final String TEXT_10 = NL;
  protected final String TEXT_11 = NL + "public class ";
  protected final String TEXT_12 = "Bean implements ";
  protected final String TEXT_13 = "Local, ";
  protected final String TEXT_14 = "Remote {" + NL + "" + NL + "\t/** @generated */" + NL + "\t@Logger" + NL + "\tprivate Log logger;" + NL + "" + NL + "\t/** @generated */" + NL + "\t@In(\"";
  protected final String TEXT_15 = "EntityManager\")" + NL + "\tprivate EntityManager entityManager;" + NL + "" + NL + "\t/** @generated */" + NL + "\tprivate EntityManager getEntityManager() {" + NL + "\t\treturn entityManager;" + NL + "\t}" + NL + "\t" + NL + "\t/** @generated */" + NL + "\t@Resource " + NL + "\tprivate SessionContext ctx;";
  protected final String TEXT_16 = NL + NL + "\t/** @generated */" + NL + "\t";
  protected final String TEXT_17 = NL + "\tprotected ";
  protected final String TEXT_18 = " ";
  protected final String TEXT_19 = ";\t";
  protected final String TEXT_20 = NL + NL + "\t/** @generated */" + NL + "\tpublic ";
  protected final String TEXT_21 = "Bean() {" + NL + "\t}";
  protected final String TEXT_22 = NL + NL + "\t/**" + NL + "\t * ";
  protected final String TEXT_23 = NL + "\t * @generated" + NL + "\t */" + NL + "\t";
  protected final String TEXT_24 = NL + "\tpublic ";
  protected final String TEXT_25 = " ";
  protected final String TEXT_26 = "(";
  protected final String TEXT_27 = ") {" + NL + "\t\t//TODO Implement operation - This is just a sample - Ensure that you remove @generated or mark it @generated NOT" + NL + "//\t\tPrincipal p = ctx.getCallerPrincipal();";
  protected final String TEXT_28 = NL + "\t\t";
  protected final String TEXT_29 = " = getEntityManager().find(";
  protected final String TEXT_30 = ".class, ";
  protected final String TEXT_31 = ".getId());" + NL + "\t\tgetEntityManager().remove(";
  protected final String TEXT_32 = ");" + NL + "\t\treturn ";
  protected final String TEXT_33 = ";";
  protected final String TEXT_34 = NL + "\t\t";
  protected final String TEXT_35 = " = getEntityManager().merge(";
  protected final String TEXT_36 = ");" + NL + "\t\treturn ";
  protected final String TEXT_37 = ";";
  protected final String TEXT_38 = NL + "\t\treturn (";
  protected final String TEXT_39 = ") getEntityManager().find(";
  protected final String TEXT_40 = ".class, id);";
  protected final String TEXT_41 = NL + "\t\tMap<String, Object> parameters = new HashMap<String, Object>();" + NL + "\t\tStringBuffer where = new StringBuffer();" + NL + "\t\t" + NL + "//\t\tQueryUtil.formatAnd(where, parameters, \"c\", \"name\", \"like\", '%' + example.getName() + '%');" + NL + "" + NL + "        //TODO NamedQuery" + NL + "\t\tQuery qry = getEntityManager().createQuery(\"select c from ";
  protected final String TEXT_42 = " c \"" + NL + "\t\t\t\t+ where.toString()" + NL + "\t\t\t\t+ \" order by c.\"" + NL + "\t\t\t\t+ orderBy);" + NL + "" + NL + "\t\tqry.setFirstResult(first.intValue());" + NL + "\t\tqry.setMaxResults(max.intValue());" + NL + "" + NL + "\t\tQueryUtil.setParameters(qry, parameters);" + NL + "\t\treturn qry.getResultList();";
  protected final String TEXT_43 = NL + "\t\tthrow new UnsupportedOperationException();\t\t";
  protected final String TEXT_44 = NL + "\t}";
  protected final String TEXT_45 = "\t" + NL + "}";
  protected final String TEXT_46 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    

    org.eclipse.uml2.uml.Interface uml2Interface = (org.eclipse.uml2.uml.Interface) argument;org.eclipse.uml2.uml.Package uml2Package = uml2Interface.getPackage();
    stringBuffer.append(TEXT_1);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(NameHelper.getQualifiedName(uml2Package));
    stringBuffer.append(TEXT_3);
    ImportManager importManager = ImportHelper.makeImportManager("");
    stringBuffer.append(TEXT_4);
    importManager.addImport("java.security.Principal");
    importManager.addImport("java.util.ArrayList");
    importManager.addImport("java.util.Collection");
    importManager.addImport("java.util.Calendar");
    importManager.addImport("java.util.HashMap");
    importManager.addImport("java.util.Iterator");
    importManager.addImport("java.util.List");
    importManager.addImport("java.util.Map");
    importManager.addImport("javax.annotation.Resource");
    importManager.addImport("javax.ejb.SessionContext");
    importManager.addImport("javax.persistence.EntityManager");
    importManager.addImport("javax.persistence.Query");
    importManager.addImport("org.jboss.seam.annotations.AutoCreate");
    importManager.addImport("org.jboss.seam.annotations.In");
    importManager.addImport("org.jboss.seam.annotations.Name");
    importManager.addImport("org.jboss.seam.annotations.Logger");
    importManager.addImport("org.jboss.seam.log.Log");
    importManager.addImport("rad.framework.jpa.QueryUtil");
    stringBuffer.append(TEXT_5);
    
StringBuffer importStringBuffer = stringBuffer;
int importInsertionPoint = stringBuffer.length();
importManager.addCompilationUnitImports(stringBuffer.toString());

    stringBuffer.append(TEXT_6);
    stringBuffer.append(TypeHelper.getDocumentation(uml2Interface));
    stringBuffer.append(TEXT_7);
    stringBuffer.append(System.getProperty("user.name"));
    stringBuffer.append(TEXT_8);
    stringBuffer.append(NameHelper.uncapSafeName(uml2Interface));
    stringBuffer.append(TEXT_9);
    stringBuffer.append(TEXT_10);
    stringBuffer.append(StereotypeHelper.getAnnotations(uml2Interface, false));
    stringBuffer.append(TEXT_11);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_12);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_13);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_14);
    stringBuffer.append(NameHelper.uncapSafeName(uml2Interface.getModel()).replace("-",""));
    stringBuffer.append(TEXT_15);
    for (Iterator i=uml2Interface.getClientDependencies().iterator(); i.hasNext();) { org.eclipse.uml2.uml.Dependency dependency = (org.eclipse.uml2.uml.Dependency)i.next();
    stringBuffer.append(TEXT_16);
    stringBuffer.append(StereotypeHelper.getAnnotations(dependency));
    stringBuffer.append(TEXT_17);
    stringBuffer.append(InterfaceHelper.getDependencyType(dependency));
    stringBuffer.append(TEXT_18);
    stringBuffer.append(InterfaceHelper.getDependencyName(dependency));
    stringBuffer.append(TEXT_19);
    }//for
    stringBuffer.append(TEXT_20);
    stringBuffer.append(NameHelper.getCapName(uml2Interface));
    stringBuffer.append(TEXT_21);
    for (Iterator i=uml2Interface.getOwnedOperations().iterator(); i.hasNext();) { org.eclipse.uml2.uml.Operation operation = (org.eclipse.uml2.uml.Operation)i.next();
    stringBuffer.append(TEXT_22);
    stringBuffer.append(TypeHelper.getDocumentation(operation));
    stringBuffer.append(TEXT_23);
    stringBuffer.append(StereotypeHelper.getAnnotations(operation));
    stringBuffer.append(TEXT_24);
    stringBuffer.append(InterfaceHelper.getReturn(operation));
    stringBuffer.append(TEXT_25);
    stringBuffer.append(operation.getName());
    stringBuffer.append(TEXT_26);
    stringBuffer.append(InterfaceHelper.getParameters(operation));
    stringBuffer.append(TEXT_27);
    if ("delete".equals(operation.getName())) {
    stringBuffer.append(TEXT_28);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_29);
    stringBuffer.append(InterfaceHelper.getFirstParameterType(operation));
    stringBuffer.append(TEXT_30);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_31);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_32);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_33);
    }else { if ("save".equals(operation.getName())) {
    stringBuffer.append(TEXT_34);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_35);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_36);
    stringBuffer.append(InterfaceHelper.getFirstParameterName(operation));
    stringBuffer.append(TEXT_37);
    }else { if ("get".equals(operation.getName()) || "find".equals(operation.getName())) {
    stringBuffer.append(TEXT_38);
    stringBuffer.append(InterfaceHelper.getReturn(operation));
    stringBuffer.append(TEXT_39);
    stringBuffer.append(InterfaceHelper.getReturn(operation));
    stringBuffer.append(TEXT_40);
    }else { if ("query".equals(operation.getName())) {
    stringBuffer.append(TEXT_41);
    stringBuffer.append(InterfaceHelper.getFirstParameterType(operation));
    stringBuffer.append(TEXT_42);
    }else {
    stringBuffer.append(TEXT_43);
    }}}}
    stringBuffer.append(TEXT_44);
    }//for
    stringBuffer.append(TEXT_45);
    importStringBuffer.insert(importInsertionPoint, importManager.computeSortedImports());
    stringBuffer.append(TEXT_46);
    return stringBuffer.toString();
  }
}
